package com.zhy.http.okhttp.https;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

public class HttpsUtils
{
  private static X509TrustManager chooseTrustManager(TrustManager[] paramArrayOfTrustManager)
  {
    int i = paramArrayOfTrustManager.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
        return null;
      TrustManager localTrustManager = paramArrayOfTrustManager[j];
      if ((localTrustManager instanceof X509TrustManager))
        return (X509TrustManager)localTrustManager;
    }
  }

  public static SSLSocketFactory getSslSocketFactory(InputStream[] paramArrayOfInputStream, InputStream paramInputStream, String paramString)
  {
    try
    {
      TrustManager[] arrayOfTrustManager1 = prepareTrustManager(paramArrayOfInputStream);
      KeyManager[] arrayOfKeyManager = prepareKeyManager(paramInputStream, paramString);
      SSLContext localSSLContext = SSLContext.getInstance("TLS");
      TrustManager[] arrayOfTrustManager2 = new TrustManager[1];
      arrayOfTrustManager2[0] = new MyTrustManager(chooseTrustManager(arrayOfTrustManager1));
      localSSLContext.init(arrayOfKeyManager, arrayOfTrustManager2, new SecureRandom());
      SSLSocketFactory localSSLSocketFactory = localSSLContext.getSocketFactory();
      return localSSLSocketFactory;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new AssertionError(localNoSuchAlgorithmException);
    }
    catch (KeyManagementException localKeyManagementException)
    {
      throw new AssertionError(localKeyManagementException);
    }
    catch (KeyStoreException localKeyStoreException)
    {
      throw new AssertionError(localKeyStoreException);
    }
  }

  private static KeyManager[] prepareKeyManager(InputStream paramInputStream, String paramString)
  {
    if ((paramInputStream == null) || (paramString == null))
      return null;
    try
    {
      KeyStore localKeyStore = KeyStore.getInstance("BKS");
      localKeyStore.load(paramInputStream, paramString.toCharArray());
      KeyManagerFactory localKeyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      localKeyManagerFactory.init(localKeyStore, paramString.toCharArray());
      KeyManager[] arrayOfKeyManager = localKeyManagerFactory.getKeyManagers();
      return arrayOfKeyManager;
    }
    catch (KeyStoreException localKeyStoreException)
    {
      localKeyStoreException.printStackTrace();
      return null;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      localNoSuchAlgorithmException.printStackTrace();
      return null;
    }
    catch (UnrecoverableKeyException localUnrecoverableKeyException)
    {
      localUnrecoverableKeyException.printStackTrace();
      return null;
    }
    catch (CertificateException localCertificateException)
    {
      localCertificateException.printStackTrace();
      return null;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      return null;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  // ERROR //
  private static TrustManager[] prepareTrustManager(InputStream[] paramArrayOfInputStream)
  {
    // Byte code:
    //   0: aload_0
    //   1: ifnull +8 -> 9
    //   4: aload_0
    //   5: arraylength
    //   6: ifgt +5 -> 11
    //   9: aconst_null
    //   10: areturn
    //   11: ldc 113
    //   13: invokestatic 118	java/security/cert/CertificateFactory:getInstance	(Ljava/lang/String;)Ljava/security/cert/CertificateFactory;
    //   16: astore 5
    //   18: invokestatic 121	java/security/KeyStore:getDefaultType	()Ljava/lang/String;
    //   21: invokestatic 77	java/security/KeyStore:getInstance	(Ljava/lang/String;)Ljava/security/KeyStore;
    //   24: astore 6
    //   26: aload 6
    //   28: aconst_null
    //   29: invokevirtual 124	java/security/KeyStore:load	(Ljava/security/KeyStore$LoadStoreParameter;)V
    //   32: aload_0
    //   33: arraylength
    //   34: istore 7
    //   36: iconst_0
    //   37: istore 8
    //   39: iconst_0
    //   40: istore 9
    //   42: iload 8
    //   44: iload 7
    //   46: if_icmplt +24 -> 70
    //   49: invokestatic 127	javax/net/ssl/TrustManagerFactory:getDefaultAlgorithm	()Ljava/lang/String;
    //   52: invokestatic 130	javax/net/ssl/TrustManagerFactory:getInstance	(Ljava/lang/String;)Ljavax/net/ssl/TrustManagerFactory;
    //   55: astore 10
    //   57: aload 10
    //   59: aload 6
    //   61: invokevirtual 133	javax/net/ssl/TrustManagerFactory:init	(Ljava/security/KeyStore;)V
    //   64: aload 10
    //   66: invokevirtual 137	javax/net/ssl/TrustManagerFactory:getTrustManagers	()[Ljavax/net/ssl/TrustManager;
    //   69: areturn
    //   70: aload_0
    //   71: iload 8
    //   73: aaload
    //   74: astore 11
    //   76: iload 9
    //   78: iconst_1
    //   79: iadd
    //   80: istore 12
    //   82: aload 6
    //   84: iload 9
    //   86: invokestatic 143	java/lang/Integer:toString	(I)Ljava/lang/String;
    //   89: aload 5
    //   91: aload 11
    //   93: invokevirtual 147	java/security/cert/CertificateFactory:generateCertificate	(Ljava/io/InputStream;)Ljava/security/cert/Certificate;
    //   96: invokevirtual 151	java/security/KeyStore:setCertificateEntry	(Ljava/lang/String;Ljava/security/cert/Certificate;)V
    //   99: aload 11
    //   101: ifnull +8 -> 109
    //   104: aload 11
    //   106: invokevirtual 156	java/io/InputStream:close	()V
    //   109: iinc 8 1
    //   112: iload 12
    //   114: istore 9
    //   116: goto -74 -> 42
    //   119: astore 4
    //   121: aload 4
    //   123: invokevirtual 107	java/security/NoSuchAlgorithmException:printStackTrace	()V
    //   126: aconst_null
    //   127: areturn
    //   128: astore_3
    //   129: aload_3
    //   130: invokevirtual 109	java/security/cert/CertificateException:printStackTrace	()V
    //   133: aconst_null
    //   134: areturn
    //   135: astore_2
    //   136: aload_2
    //   137: invokevirtual 106	java/security/KeyStoreException:printStackTrace	()V
    //   140: aconst_null
    //   141: areturn
    //   142: astore_1
    //   143: aload_1
    //   144: invokevirtual 111	java/lang/Exception:printStackTrace	()V
    //   147: aconst_null
    //   148: areturn
    //   149: astore 13
    //   151: goto -42 -> 109
    //
    // Exception table:
    //   from	to	target	type
    //   11	36	119	java/security/NoSuchAlgorithmException
    //   49	70	119	java/security/NoSuchAlgorithmException
    //   70	76	119	java/security/NoSuchAlgorithmException
    //   82	99	119	java/security/NoSuchAlgorithmException
    //   104	109	119	java/security/NoSuchAlgorithmException
    //   11	36	128	java/security/cert/CertificateException
    //   49	70	128	java/security/cert/CertificateException
    //   70	76	128	java/security/cert/CertificateException
    //   82	99	128	java/security/cert/CertificateException
    //   104	109	128	java/security/cert/CertificateException
    //   11	36	135	java/security/KeyStoreException
    //   49	70	135	java/security/KeyStoreException
    //   70	76	135	java/security/KeyStoreException
    //   82	99	135	java/security/KeyStoreException
    //   104	109	135	java/security/KeyStoreException
    //   11	36	142	java/lang/Exception
    //   49	70	142	java/lang/Exception
    //   70	76	142	java/lang/Exception
    //   82	99	142	java/lang/Exception
    //   104	109	142	java/lang/Exception
    //   104	109	149	java/io/IOException
  }

  private static class MyTrustManager
    implements X509TrustManager
  {
    private X509TrustManager defaultTrustManager;
    private X509TrustManager localTrustManager;

    public MyTrustManager(X509TrustManager paramX509TrustManager)
      throws NoSuchAlgorithmException, KeyStoreException
    {
      TrustManagerFactory localTrustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      localTrustManagerFactory.init(null);
      this.defaultTrustManager = HttpsUtils.chooseTrustManager(localTrustManagerFactory.getTrustManagers());
      this.localTrustManager = paramX509TrustManager;
    }

    public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString)
      throws CertificateException
    {
    }

    public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString)
      throws CertificateException
    {
      try
      {
        this.defaultTrustManager.checkServerTrusted(paramArrayOfX509Certificate, paramString);
        return;
      }
      catch (CertificateException localCertificateException)
      {
        this.localTrustManager.checkServerTrusted(paramArrayOfX509Certificate, paramString);
      }
    }

    public X509Certificate[] getAcceptedIssuers()
    {
      return new X509Certificate[0];
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.zhy.http.okhttp.https.HttpsUtils
 * JD-Core Version:    0.6.2
 */